package com.sun.showcase.controller.mall;

import com.sun.showcase.biz.mall.service.HomeGoodsService;
import com.sun.showcase.client.domain.mall.HomeGoods;
import com.sun.showcase.client.query.mall.HomeGoodsQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value="/mall/homeGoods")
public class HomeGoodsController{
	
	@Autowired
	private HomeGoodsService homeGoodsService;
	
	private Result result = new Result();
	/**
	 * 跳转到HomeGoods管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goHomeGoods")
	public String goHomeGoods() {
		return "mall/homeGoods";
	}
	/**
	 * 跳转到HomeGoods新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleHomeGoods")
	public String handleHomeGoods(@RequestParam(value="id",required=false) Long id , ModelMap map) {
		return "mall/homeGoods_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public HomeGoods showDesc(HomeGoodsQuery homeGoodsQuery) {
		return homeGoodsService.get(homeGoodsQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(HomeGoodsQuery homeGoodsQuery) {
		return homeGoodsService.datagrid(homeGoodsQuery);
	}
	

	/**
	 * 添加一个HomeGoods
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(HomeGoodsQuery homeGoodsQuery) {
		homeGoodsService.add(homeGoodsQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑HomeGoods
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(HomeGoodsQuery homeGoodsQuery) {
		homeGoodsService.update(homeGoodsQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除HomeGoods
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(HomeGoodsQuery homeGoodsQuery) {
		homeGoodsService.delete(homeGoodsQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除HomeGoods
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(HomeGoodsQuery homeGoodsQuery) {
		homeGoodsService.deletePt(homeGoodsQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据HomeGoods
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(HomeGoodsQuery homeGoodsQuery) {
		List<HomeGoodsQuery> list = homeGoodsService.listAll(homeGoodsQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
